"""
I	1
V	5
X	10
L	50
C	100
D	500
M	1000
"""
class Solution:
    def romanToInt(self, s: str) -> int:
        list0 = list(s)
        dict1 = {
            'I': 1,
            'V': 5,
            'X': 10,
            'L': 50,
            'C': 100,
            'D': 500,
            'M': 1000
        }
        num = 0
        if (len(list0) == 1):
            return dict1[list0[0]]
        flag = 0
        for index, n in enumerate(list0[::-1], 1):
            if dict1[n] < flag:
                num -= dict1[n]
            else:
                num += dict1[n]
            flag = dict1[n]
        return num


lll = Solution()
print(lll.romanToInt('MCMXCIV'))
